const values_default = {
  company_id: 2001
}

const domain_default = {}

const fields_default = {
  name: null,
  company_id: null,
  parent_id: null,
  manager_id: null,
  child_ids: null,
  member_ids: null,
  jobs_ids: null

  // child_ids: { name: null, display_name: null },
  // member_ids: { name: null, display_name: null },
  // jobs_ids: { name: null, display_name: null }
}

const filterItems = [
  { type: 'input', name: 'name___like', placeholder: '名称' },
  { type: 'select', name: 'parent_id', placeholder: '父部门' }
]

const columns = [
  { name: 'name', type: 'char', label: '名称' },
  { name: 'company_id__name', type: 'char', label: '公司' },
  { name: 'parent_id__name', type: 'char', label: '上级部门' },
  { name: 'manager_id__name', type: 'char', label: '部门经理' },
  { name: 'child_ids__count', type: 'char', label: '下级部门' },
  { name: 'member_ids__count', type: 'char', label: '部门的员工' },
  { name: 'jobs_ids__count', type: 'char', label: '部门的职位' }
]

const formItems = [
  { type: 'input', name: 'name', label: '名称' },
  {
    type: 'select',
    name: 'parent_id',
    label: '上级部门',
    rules: { required: false },
    options: {
      // 设置一个 空值的 options,  需要 初始化 options_for_select
      // options : undefined, 无需初始化 options_for_select
    },

    options_for_select: params => {
      const { row, options_for_select } = params
      // 设置parent_id 时, 不能是自己以及自己的子孙 TBD
      return options_for_select.filter(item => item.id !== row.id)
    },

    placeholder: '上级部门'
  },
  {
    type: 'select',
    name: 'manager_id',
    label: '部门经理',
    rules: { required: false },
    placeholder: '部门经理'
  }
]

const child_configs = {
  child_ids: {
    label: '下级部门',
    columns: [
      { name: 'name', type: 'char', label: '名称' },
      { name: 'manager_id__name', type: 'char', label: '部门经理' },
      { name: 'child_ids__names', type: 'char', label: '下级部门' },
      { name: 'member_ids__names', type: 'char', label: '部门的员工' },
      { name: 'jobs_ids__names', type: 'char', label: '部门的职位' }
    ],

    formItems: [
      { type: 'input', name: 'name', label: '名称' },
      {
        type: 'select',
        name: 'manager_id',
        label: '部门经理',
        rules: { required: false },
        placeholder: '部门经理'
      }
    ]
  },

  member_ids: {
    label: '部门员工',
    columns: [{ name: 'name', type: 'char', label: '名称' }],

    formItems: [{ type: 'input', name: 'name', label: '名称' }]
  }
}

const Model = {
  // name: 'res.partner',
  configs: {
    values_default,
    domain_default,
    fields_default,
    filterItems,
    columns,
    formItems,
    child_configs
  },

  extend: BaseClass => {
    class ModelClass extends BaseClass {
      global_domain(domain_src = {}) {
        // console.log('this.global_domain in odoo.res.partner')
        const domain = { ...domain_src }
        // const userinfo = self.get_userinfo()
        // const { uid } = userinfo
        // domain.user_id = uid
        return super.global_domain(domain)
      }
    }
    return ModelClass
  }
}

export default Model
